﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Knlght.Domain
{
    /// <summary>
    /// 分页对象集合回复类
    /// </summary>
    public class PagingResponse<T> : ResponseBase
    {
        public PagingResponse(bool isSuccess = true, string error = "", int resultCode = -1) : base(isSuccess, error, resultCode)
        { }
        /// <summary>
        /// 获取到的回复对象集合
        /// </summary>
        public List<T> Models { get; set; }
        /// <summary>
        /// 总模型数
        /// </summary>
        public int TotalModels { get; set; }
        /// <summary>
        /// 总页数
        /// </summary>
        public int TotalPages { get; set; }

        #region 辅助方法
        /// <summary>
        /// 创建 成功获取单个对象的回复对象
        /// </summary>
        public static PagingResponse<T> CreateResponseBySuccess(List<T> models, int totalModels, int totalPages)
        {
            return new PagingResponse<T>(true) { Models = models, TotalModels = totalModels, TotalPages = totalPages };
        }
        /// <summary>
        /// 获取操作失败的回复对象
        /// </summary>
        public static PagingResponse<T> CreateResponseByFail(string error, int resultCode = ResultCodeConstants.NONE)
        {
            return new PagingResponse<T>(false, error, resultCode);
        }
        #endregion
    }
}
